import * as types from './mutations_types.js';

let setDefaultState = (Val, defaultVal) => {
  return Val == undefined ? defaultVal : Val;
};

export default {
  [types.SET_SYSLANGUAGE](state, active) {
    state.sysLanguage.active = setDefaultState(active, state.sysLanguage.active);
  },
  [types.FULLSCREENTABLE_TOGGLE](state, isFullScreenTable) {
    state.isFullScreenTable = setDefaultState(isFullScreenTable, !state.isFullScreenTable);
  },
  [types.ISMASK_TOGGLE](state, isMask) {
    state.isMask = setDefaultState(isMask, !state.isMask);
  },
  [types.LOADING_TOGGLE](state, isLoading) {
    state.isLoading = setDefaultState(isLoading, !state.isLoading);
  },
  [types.TOAST_TOGGLE](state, isToasting) {
    state.isToasting = setDefaultState(isToasting, !state.isToasting);
  },
  [types.SET_TOAST](state, toast) {
    state.toast.info = setDefaultState(toast.info, state.toast.info);
    state.toast.icon = setDefaultState(toast.icon, state.toast.icon);
    state.toast.time = setDefaultState(toast.time, state.toast.time);
    state.toast.onHidden = setDefaultState(toast.onHidden, null);
  },
  [types.SIDEBAR_TOGGLE](state, isHideSideBar) {
    state.isHideSideBar = setDefaultState(isHideSideBar, !state.isHideSideBar);
  },
  [types.SET_ALLMENU](state, allMenu) {
    state.allMenu.list = setDefaultState(allMenu.list, state.allMenu.list);
    state.allMenu.active = setDefaultState(allMenu.active, state.allMenu.active);
  },
  [types.SET_SIDEMENULIST](state, sideMenu) {
    state.sideMenu.list = setDefaultState(sideMenu.list, state.sideMenu.list);
    state.sideMenu.firstIndex = setDefaultState(sideMenu.firstIndex, state.sideMenu.firstIndex);
  },
  [types.SET_TABLIST](state, tab) {
    state.tab.list = setDefaultState(tab.list, state.tab.list);
    state.tab.active = setDefaultState(tab.active, state.tab.active);
  },
  [types.SET_SYNCHRONIZEMENU](state, isSynchronize) {
    state.tab.isSynchronize = setDefaultState(isSynchronize, !state.tab.isSynchronize);
  },
  [types.SET_MODAL](state, modal) {
    state.modal.active = setDefaultState(modal.active, state.modal.active);
    state.modal.deactive = setDefaultState(modal.deactive, state.modal.deactive);
  },
  [types.DIALOG_TOGGLE](state, isDialog) {
    state.dialog.isDialog = setDefaultState(isDialog, !state.dialog.isDialog);
  },
  [types.SET_DIALOG](state, dialog) {
    state.dialog.title = setDefaultState(dialog.title, state.dialog.title);
    state.dialog.contents = setDefaultState(dialog.contents, state.dialog.contents);
    state.dialog.btnGroup = setDefaultState(dialog.btnGroup, state.dialog.btnGroup);
    state.dialog.confirmCallback = setDefaultState(dialog.confirmCallback, state.dialog.confirmCallback);
    state.dialog.cancelCallback = setDefaultState(dialog.cancelCallback, state.dialog.cancelCallback);
    state.dialog.tipText = setDefaultState(dialog.tipText, state.dialog.tipText);
  },
  [types.SET_PERMS](state, perms) {
    state.perms = perms;
  },
  [types.SET_PERMS](state, perms) {
    state.perms = perms;
  },
  [types.SET_NEEPADDPARKINGLOTINGLOT](state, payload) {
    state.needAddParkinglotFirst = payload;
  },
  // 键盘相关事函数
  changeNum_KB(state, boolean) {
    state.keyBoard.isNumber = typeof boolean == 'undefined' ? !state.keyBoard.isNumber : boolean;
  },
  changeShow_KB(state, payload) {
    state.keyBoard.isShow = payload.bool;
    if (payload.urlPic) {
      state.keyBoard.previewPic = payload.urlPic;
    }
  },
  serVal_KB(state, carCode) {
    state.keyBoard.Val = carCode;
  },
  init_KB(state) {
    state.keyBoard = {
      isNumber: false,
      Val: '',
      isShow: false
    };
  },
  setLogoObj(state, Obj) {
    state.logoObj = Obj;
  },
  setCarrierId(state, Obj) {
    state.carrierId = Obj;
  },
  setSkinType(state, val) {
    state.skinType = val;
  },
  setUserInfo(state, payload) {
    state.userInfo = payload || {};
  },
};
